package ${cfg.basePath}.service.impl;

import ${cfg.basePath}.entity.${cfg.moduleName}${entity};
import ${cfg.basePath}.mapper.${cfg.moduleName}${entity}Mapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${cfg.basePath}.service.${table.serviceName};
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import javax.annotation.Resource;
import com.example.suuu.model.PagVo;
import com.example.suuu.project.system.query.${entity}Query;

/**
* <p>
    * ${table.comment!} 服务实现类
    * </p>
*
* @author sun
* @date ${date}
*/
@Transactional
@Service
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName}{

    @Resource
    private ${table.mapperName} ${table.entityPath}Mapper;


    /**
    * 查询全部
    */
    @Override
    public List<${entity}> getList(${entity} u){
        return ${table.entityPath}Mapper.getList(u);
    };
    /**
    * 查询总数
    */
    @Override
    public Long count(${entity} u){
        return ${table.entityPath}Mapper.count(u);
    };
    /**
    * 查询单个
    */
    @Override
    public ${entity} getById(Integer id){
        return ${table.entityPath}Mapper.getById(id);
    };
    /**
    * 新增
    */
    @Override
    public int add(${entity} u){
        u.setIsdel(1);
        u.setCreatetime(LocalDateTime.now());
        u.setUpdatetime(LocalDateTime.now());
        return ${table.entityPath}Mapper.add(u);
    };
    /**
    * 修改
    */
    @Override
    public int update(${entity} u){
        u.setUpdatetime(LocalDateTime.now());
        return ${table.entityPath}Mapper.update(u);
    };
    /**
    * 删除
    */
    @Override
    public int del(Integer id){
        return ${table.entityPath}Mapper.del(id);
    };

    /**
    * 分页区分方法
    */
    @Override
    public Object pagVo(${entity}Query query){
        ${entity} u = new ${entity}();
        u.setIsdel(1);
        if (query.getCurrentPage() != null && query.getPageSize() != null) {
            u.setCurrentPage((query.getCurrentPage()-1)*query.getPageSize());
            u.setPageSize(query.getPageSize());
            PagVo p = new PagVo();
            p.setCount(count(u));
            p.setList(getList(u));
            return p;
        }
        return getList(u);
    };
}